
public class IfFunction extends Function{

	{
		order = 3;
	}
    
	public double evaluate(double[] vars){
		boolean check = children.get(0).evaluate(vars) > 0;
		double first = children.get(1).evaluate(vars);
		double second = children.get(2).evaluate(vars);
		
		return check ? first : second;
	}
	
	public IfFunction deepCopy(){
		IfFunction returner = new IfFunction();
		for(Node myChild:this.children){
			returner.children.add(myChild.deepCopy());
		}
		for(Node otherChild:returner.children){
			otherChild.parent = returner;
		}
		returner.size = this.size;
		return returner;
	}
	
	public String toString() {
		return "if("+this.children.get(0)+" ) then( "+this.children.get(1)
		+" ) else( "+this.children.get(2)+" )";
	}
}
